/*
Copyright [2020] [https://www.xiaonuo.vip]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：

1.请不要删除和修改根目录下的LICENSE文件。
2.请不要删除和修改Snowy源码头部的版权声明。
3.请保留源码和相关描述文件的项目出处，作者声明等。
4.分发源码时候，请注明软件出处 https://gitee.com/xiaonuobase/snowy
5.在修改包名，模块名称，项目代码等时，请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点，可申请商业授权，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.modular.usertrace.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.questionnaire.param.QuestionnaireParam;
import vip.xiaonuo.modular.usertrace.param.UserTraceParam;
import vip.xiaonuo.modular.usertrace.service.UserTraceService;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 * 账户流水控制器
 *
 * @author wanglei
 * @date 2021-08-25 18:59:05
 */
@Api(tags = "用户流水")
@RestController
public class UserTraceController {

    @Resource
    private UserTraceService userTraceService;

    /**
     * 查询账户流水
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @GetMapping("/userTrace/page")
    @ApiOperation("查询所有账户流水")
    @BusinessLog(title = "账户流水_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(UserTraceParam userTraceParam) {
        return new SuccessResponseData(userTraceService.page(userTraceParam));
    }

    /**
     * 添加账户流水
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @PostMapping("/userTrace/add")
    @ApiOperation("添加账户流水")
    @BusinessLog(title = "账户流水_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody  @Validated(QuestionnaireParam.add.class) UserTraceParam userTraceParam) {
            userTraceService.add(userTraceParam);
        return new SuccessResponseData();
    }

    /**
     * 删除账户流水，可批量删除
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @PostMapping("/userTrace/delete")
    @ApiOperation("账户流水_删除")
    @BusinessLog(title = "账户流水_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody   @Validated(QuestionnaireParam.delete.class) List<UserTraceParam> userTraceParamList) {
            userTraceService.delete(userTraceParamList);
        return new SuccessResponseData();
    }

    /**
     * 编辑账户流水
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @PostMapping("/userTrace/edit")
    @BusinessLog(title = "账户流水_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody  @Validated(QuestionnaireParam.edit.class) UserTraceParam userTraceParam) {
            userTraceService.edit(userTraceParam);
        return new SuccessResponseData();
    }

    /**
     * 查看账户流水
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @PostMapping("/userTrace/detail")
    @ApiOperation("*查看账户流水详细")
    @BusinessLog(title = "账户流水_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@RequestBody UserTraceParam userTraceParam) {
        return new SuccessResponseData(userTraceService.detail(userTraceParam));
    }

    /**
     * 账户流水列表
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @GetMapping("/userTrace/list")
    @ApiOperation("账户流水列表")
    @BusinessLog(title = "账户流水_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(UserTraceParam userTraceParam) {
        return new SuccessResponseData(userTraceService.list(userTraceParam));
    }

    /**
     * 根据用户查询流水
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @GetMapping("/userTrace/getByPhone")
    @ApiOperation("根据用户查询流水")
    @BusinessLog(title = "根据用户查询流水", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getByPhone(@RequestParam String Phone) {
        return new SuccessResponseData(userTraceService.selectByPhones(Phone));
    }

    /**
     * 根据用户id统计流水
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @GetMapping("/userTrace/getAllTurnover")
    @ApiOperation("账户流水根据手机号获取")
    public ResponseData getAllTurnover(@RequestParam String phone, @RequestParam(required = false) Integer month) {
        try {
            return new SuccessResponseData(userTraceService.selectAllTurnover(phone, month));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    @GetMapping("/userTrace/getLumpSum")
    @ApiOperation("账户流水根据手机号获取总额")
    @BusinessLog(title = "账户流水根据手机号获取总额")
    public ResponseData getLumpSum(@RequestParam String phone) {
        return new SuccessResponseData(userTraceService.getLumpSum(phone));
    }

    @GetMapping("/userTrace/getTodaySWithdrawalLimit")
    @ApiOperation("获取今日提现额度")
    @BusinessLog(title = "获取今日提现额度", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getTodaySWithdrawalLimit(@RequestParam String phone) {
        return new SuccessResponseData(userTraceService.getTodaySWithdrawalLimit(phone));
    }

    /**
     * 导出系统用户
     *
     * @author wanglei
     * @date 2021-08-25 18:59:05
     */
    @GetMapping("/userTrace/export")
    @ApiOperation("导出系统用户")
    @BusinessLog(title = "账户流水_导出", opType = LogAnnotionOpTypeEnum.EXPORT)
    public void export(UserTraceParam userTraceParam) {
        userTraceService.export(userTraceParam);
    }


    /**
     * 首页根据用户手机号统计上架收入资产
     * @author xiyumo
     * @date 2021/12/31 10:56
     */
    @GetMapping("/userTrace/property")
    @ApiOperation("*首页根据用户手机号统计上架收入资产")
    public ResponseData property(@RequestParam String phone, @RequestParam(required = false) Integer month) {
        try {
            return new SuccessResponseData(userTraceService.property(phone, month));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    @GetMapping("/userTrace/getSum")
    @ApiOperation("*根据手机号获取我的钱包总额")
    @BusinessLog(title = "根据手机号获取我的钱包总额")
    public ResponseData getSum(@RequestParam String phone) {
        return new SuccessResponseData(userTraceService.getSum(phone));
    }

    @GetMapping("/userTrace/userList")
    @ApiOperation("*根据手机号查询用户账户流水列表")
    @BusinessLog(title = "用户流水_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData userList(@RequestParam String phone) {
        return new SuccessResponseData(userTraceService.userList(phone));
    }
}
